Release 10.1A: OpenEdge Getting Started:
Object-oriented Programming
Using the INTERFACE construct
An interface is a special type of class that defines only method names and signatures, along with any temp-table and ProDataSet definitions used as parameters to those methods. The interface definition specifies a main block that begins with an
INTERFACEstatement that names the interface. Only one interface can be defined per source file. An interface source file has a.clsfile extension like any other class, and its filename must match the interface name defined in theINTERFACEstatement. TheINTERFACEstatement must be the first statement in the interface. The last statement in an interface must be theENDINTERFACEstatement, which terminates the main block of the interface. An interface compiles to r-code like any other class.Interfaces are always publicly scoped and available to all other classes and procedures within an application. Thus, an interface is the way to enforce a common set of methods for related objects. All objects that implement the same interface are guaranteed to support the common set of methods defined by the interface.
The main block of the interface contains statements that specify the method names and signatures that any class implementing the interface must define. Interfaces do not contain any data members but might contain temp-table and ProDataSet definitions that are used for parameters in specified method prototypes. No allocation is associated with these definitions. These temp-table and ProDataSet definitions must be specified before any method prototypes in the main block of the interface. Any class implementing an interface with temp-table or ProDataSet parameters must repeat those definitions within the class.
When compiling a class that implements an interface with temp-table or ProDataSet parameters, the definition of a given temp-table or ProDataSet in the implementing class must be compatible with the definition of the corresponding temp-table or ProDataSet in the interface. The compiler's compatibility rules are the same as those enforced when passing temp-table or ProDataSet parameters:
- Compatible temp-tables must have the same number of fields, with each field matching in data type, extent, and position, but not in field name or any other field attribute. The temp-tables must have the same number of indexes, with index components matching in every way (except in field name), and the index names must also match. The temp-table names do not have to match.
- Compatible ProDataSets must have the same number of member buffers, in the same order, and the tables of those buffers must match in the same way as compatible temp-tables. Names of either the ProDataSet or its buffers do not have to match.
This is the syntax for defining an interface:
Element descriptions for this syntax diagram follow:
type-nameA character string that identifies the type name for an interface definition. This character string has the following syntax:
packageA character string that specifies a period-separated list of components that, along with
Note: Do not place a class file in a directory whose name contains a period (interface-name, uniquely identify the interface among all classes and interfaces. The components are based on a valid directory pathname relative toPROPATH, where each component maps to a directory level in the path and each forward or backward slash separator in the path is replaced with a period (.). If specified, the relative pathname represented bypackagespecifies the location of the class file that contains the interface definition. Anypackagespecification must remain constant between compile time and run time..) character. Progress interprets the component after the period as another directory level and will therefore not find the referenced class file.interface-nameA character string that specifies an interface name. This name must match the name of a class file (excluding the
.clsor.rextension) that contains the definition for the specified interface. This class file must be located in the relative path represented bypackage, if specified. Theinterface-namemust begin with an alphabetic character and it cannot contain a period. This name thus represents the unqualified name of the defined interface. Do not specify an interface name using a Progress reserved keyword or built-in Progress data type name, such asINTEGER.If
packageorinterface-namecontains embedded spaces, you must enclose the entire type name specification in quotes.For example, an interface with the type name
Note: The requirement to maintain a constant relative path between compile time and run time applies only to class files (not to procedure files).topdir.subdir.SomeInterfacemust be found, at compile-time, as the source fileSomeInterface.cls, in the directorytopdir/subdirrelative to thePROPATH. If the interface is compiled and saved, its r-code must be found at run time in the fileSomeInterface.rand in the same directory path,topdir/subdir, relative to thePROPATH.temp-table|ProDataSetThe interface must supply temp-table and ProDataSet definitions for any temp-tables and ProDataSets used as parameters to methods defined for the interface. These are data definitions only. The class that implements this interface must define a data member that matches each data definition in the interface.
methodSpecifies each method of the class. Each method is specified by a single
METHODstatement, a prototype with a signature, but with no implementation and noENDMETHODstatement. All methods are public and aPUBLICaccess mode must be explicitly specified for each method prototype contained in an interface file. Interfaces cannot contain constructors or destructors. The class that implements this interface must fully define a corresponding method that matches each method prototype in the interface.
|
Copyright © 2005 Progress Software Corporation www.progress.com Voice: (781) 280-4000 Fax: (781) 280-4095 |